<template>
  <div>
    <div class="search-content">
      <div class="putaway-time-wrapper">
        <span class="putaway-time-label">生效时间：</span>
        <el-date-picker
          v-model="searchContent.addTime"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
        
      </div>
     <span class="fs16">状态：</span>
      <el-select v-model="searchContent.status" placeholder="请选择">
         <el-option key="1" label="成功" value="1"></el-option>
         <el-option key="0" label="失败" value="0"></el-option>
      </el-select>
       <span class="fs16">操作人：</span>
    <el-input v-model="searchContent.name" placeholder="请输入操作人" class="input w200"></el-input>

      <span class="fs16">标题：</span>
      <el-input v-model="searchContent.remarks" placeholder="请输入内容" class="input w200"></el-input>
      <el-button type="primary" @click="search">搜索</el-button>
      <el-button type="primary" @click="resetSearchData">重置</el-button>
    </div>
    <div class="search-list">
      <el-table :data="groupList" border :height="oHeight">
        <el-table-column
          align="center"
          prop="long_url"
          label="原网址"
          min-width="120"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="short_url"
          label="短网址"
          min-width="120"
        ></el-table-column>
       
    
        <el-table-column
          align="center"
          label="生成时间"
          min-width="120"
        >
          <template slot-scope="scope">
            <span>{{
              (scope.row.createTime) | dateFormatter('YYYY-MM-DD hh:mm:ss')
            }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column
          align="center"
          prop="status"
          label="状态"
          min-width="120"
        >
         <template slot-scope="scope">
            {{ scope.row.status == 1 ? "成功" : "失败" }}
          </template>
        </el-table-column> -->
        <el-table-column
          align="center"
          prop="admin_name"
          label="操作人"
          min-width="120"
        >
        </el-table-column>

         <el-table-column
          align="center"
          prop="remarks"
          label="标题"
          min-width="120"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="复制链接"
          label="操作"
          min-width="120"
          #default={row}>
            <div v-if="row.status == 1" @click="copyUrl" class="short-link" :data-clipboard-text="row.short_url">
              <span class="copy">
                  复制短网址
              </span>
            </div>
        </el-table-column>
      </el-table>
      <div class="bottom">
        <!--分页部分-->
        <div class="paginationOne">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="searchContent.currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="searchContent.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { resize } from "@/common/js/height.js";
import { dateFormatter } from "../../../../common/js/util";
import Clipboard from "clipboard";
export default {
  data() {
    return {
      options: [],
      oHeight: 800,
      searchContent: {
        long_url: "",
        short_url: "",
        status: "",
        remarks: "",
        admin_name: "",
        create_time: "",
        currentPage: 1,
        pageSize: 20,
      },
      groupList: [],
      total: 0,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleSizeChange(pageSize) {
      this.searchContent.pageSize = pageSize;
      this.searchContent.currentPage = 1;
      this.getList();
    },
    handleCurrentChange(page) {
      this.searchContent.currentPage = page;
      this.getList();
    },
    resetSearchData() {
      this.searchContent.name = "";
      this.searchContent.status = "";
      this.searchContent.remarks = "";
      this.searchContent.addTime = "";
    },
    ////// 店铺详情总列表
    getList() {
      const data = {};
      data.page = this.searchContent.currentPage;
      data.limit = this.searchContent.pageSize;
      data.name =this.searchContent.name ;
      data.status =this.searchContent.status;
      data.remarks =this.searchContent.remarks;
    
      if (this.searchContent.addTime) {
        data.start_time = dateFormatter(
          "YYYY-MM-DD 00:00:00",
          this.searchContent.addTime[0]
        );
        data.end_time = dateFormatter(
          "YYYY-MM-DD 23:59:59",
          this.searchContent.addTime[1]
        );
      }
      // console.log("data===============", data);
      this.$http
        .post("/admin/shortUrl/index.php?act=operation&op=list", data)
        .then((res) => {
          if (res.code == 1) {
            if (res.data && res.data.list) {
              res.data.list.forEach(element => {
                element.createTime = element.create_time * 1000;
              });
              this.groupList = res.data.list;
              this.total = parseInt(res.data.count);
            } else {
              this.groupList = [];
              this.total = 0;
            }
          } else if (res.code == 2001) {
            this.groupList = [];
            this.total = 0;
          } else {
            alert(res.msg);
          }
        });
    },
    search() {
      this.getList();
    },
    copyUrl(e) {
        // 复制链接
        const clipboard = new Clipboard('.short-link')
        clipboard.on('success', e => {
            this.$message.success('已成功复制到剪切板')
            clipboard.destroy() // 释放
        })
        clipboard.on('error', e => {
            this.$message.error('复制失败')
            clipboard.destroy() // 释放
        })
    }       
   
  },
  mounted() {
    resize(this);
  },
};
</script>
<style lang="scss" scoped>
.search-content {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  &-input {
    width: 200px;
  }
  .fs16 {
    & + .el-select, & + .el-input {
      margin-left: 0;
    }
  }
  .putaway-time-wrapper {
    .putaway-time-label {
      font-size: 14px;
    }
    display: flex;
    align-items: center;
    /deep/.el-range-separator {
      box-sizing: content-box;
    }
  }
}
.bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.copy {
  color: #4395ff;
  cursor: pointer;
}
</style>